package traffic;

import input.Inputs;

enum State {

    RED {
        @Override
        State handle(Inputs input) {
            System.out.println("RED state handled");
            if (input == Inputs.TIMESTEP) {
                System.out.println("[RED] colour cycle");
                return REDYELLOW;
            }
            if (input == Inputs.CARAPPROACHES) {
                System.out.println("[RED] car approaching, turning green...");
                return GREEN;
            }
            return RED;
        }
    },
    REDYELLOW {
        @Override
        State handle(Inputs input) {
            System.out.println("REDYELLOW state handled");
            if (input == Inputs.TIMESTEP) {
                System.out.println("[REDYELLOW] colour cycle");
                return GREEN;
            }
            return REDYELLOW;
        }
    },
    GREEN {
        @Override
        State handle(Inputs input) {
            System.out.println("GREEN state handled");
            if (input == Inputs.TIMESTEP) {
                System.out.println("[GREEN] colour cycle");
                return YELLOW;
            }
            if (input == Inputs.BUTTONPEDESTRIAN) {
                System.out.println("[GREEN] pedestrian pressed button, turning red...");
                return RED;
            }
            return GREEN;
        }
    },
    YELLOW {
        @Override
        State handle(Inputs input) {
            System.out.println("YELLOW state handled");
            if (input == Inputs.TIMESTEP) {
                System.out.println("[YELLOW] colour cycle");
                return RED;
            }
            return YELLOW;
        }
    };

    abstract State handle(Inputs input);
}
